/**
 * @class AutoTestApp.controller.Lists
 * @extends Ext.app.Controller
 */
Ext.define('AutoTestApp.controller.Lists', {
    extend: 'Ext.app.Controller',

    models: ['List'],
    stores: ['lists.AutoTestLists', 'lists.BasicSettingLists', 'lists.StatisticsLists'],
    views: [ 'lists.BasicSettingTree', 'lists.AutoTestTree', 'lists.StatisticsTree', 
			 'CenterPanel.CenterPanel' ],

    refs: [
        {
            ref: 'autoTestTree',
            selector : 'view-lists-AutoTestTree'
        },{
            ref: 'basicSettingTree',
            selector : 'view-lists-BasicSettingTree'
        },{
            ref: 'statisticstTree',
            selector : 'view-lists-StatisticsTree'
        },{
            ref: 'centerPanel',
            selector : 'view-CenterPanel-AutoTestCenterPanel'
        }
    ],

    init: function() {
        var me = this;

        me.control({
            'view-lists-AutoTestTree': {
                itemclick: me.handleItemClick
            }, 
			'view-lists-BasicSettingTree': {
                itemclick: me.handleItemClick
            }, 
			'view-lists-StatisticsTree': {
                itemclick: me.handleItemClick
			}
        });
    },

	/**
     * Handles a click on the tree item .
     * @param {Ext.Component} component
     * @param {Ext.EventObject} e
     */
    handleItemClick: function(component, e) {
		centerPanel = this.getCenterPanel();
		var tab = Ext.getCmp(e.data.model + '_id')
		if (typeof(tab) === 'undefined' || tab === null) {
			tab = centerPanel.add(Ext.create(e.data.model, { 
				id : e.data.model + '_id', 
				title : e.data.name, 
				closable : true 
			}));
		}
		centerPanel.setActiveTab(tab);
    }
});
